# Author: williamjcm <w.jcm59@gmail.com>
# Contributor: mosra <mosra@centrum.cz>
# Based on the Magnum Arch Linux PKGBUILD maintained by xyproto and the MSYS2/MinGW PKGBUILD templates

_realname=magnum
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=2020.06
pkgrel=1
pkgdesc='C++11/C++14 graphics middleware for games and data visualization'
arch=('any')
url='https://magnum.graphics/'
license=('MIT')
depends=("${MINGW_PACKAGE_PREFIX}-corrade>=$pkgver"
         "${MINGW_PACKAGE_PREFIX}-openal"
         "${MINGW_PACKAGE_PREFIX}-SDL2"
         "${MINGW_PACKAGE_PREFIX}-glfw"
         "${MINGW_PACKAGE_PREFIX}-vulkan-loader")
makedepends=("${MINGW_PACKAGE_PREFIX}-cmake" "${MINGW_PACKAGE_PREFIX}-ninja" 'git')
optdepends=("${MINGW_PACKAGE_PREFIX}-magnum-plugins: import and export features"
            "${MINGW_PACKAGE_PREFIX}-magnum-integration: integrations with third-party math and physics libraries")
makedepends=("${MINGW_PACKAGE_PREFIX}-cmake" "${MINGW_PACKAGE_PREFIX}-ninja" 'unzip')
source=("${_realname}-${pkgver}.zip::https://github.com/mosra/magnum/archive/v${pkgver}.zip")
noextract=("${_realname}-${pkgver}.zip")
sha256sums=('78c52bc403cec27b98d8d87186622ca57f8d70ffd64342fe4094c720b7d3b0e3')

prepare() {
  cd ${srcdir}
  rm -rf ${_realname}-${pkgver}
  unzip ../${_realname}-${pkgver}.zip
}

build() {
    mkdir -p "${srcdir}"/build-${CARCH} && cd "${srcdir}"/build-${CARCH}

    declare -a extra_config
    if check_option "debug" "n"; then
        extra_config+=("-DCMAKE_BUILD_TYPE=Release")
    else
        extra_config+=("-DCMAKE_BUILD_TYPE=Debug")
    fi

    MSYS2_ARG_CONV_EXCL="-DCMAKE_INSTALL_PREFIX=" \
        ${MINGW_PREFIX}/bin/cmake \
            -G'Ninja' \
            -DCMAKE_INSTALL_PREFIX=${MINGW_PREFIX} \
            -DWITH_AL_INFO=ON \
            -DWITH_ANYAUDIOIMPORTER=ON \
            -DWITH_ANYIMAGECONVERTER=ON \
            -DWITH_ANYIMAGEIMPORTER=ON \
            -DWITH_ANYSCENEIMPORTER=ON \
            -DWITH_ANYSCENECONVERTER=ON \
            -DWITH_AUDIO=ON \
            -DWITH_DISTANCEFIELDCONVERTER=ON \
            -DWITH_WGLCONTEXT=ON \
            -DWITH_IMAGECONVERTER=ON \
            -DWITH_MAGNUMFONT=ON \
            -DWITH_MAGNUMFONTCONVERTER=ON \
            -DWITH_OBJIMPORTER=ON \
            -DWITH_OPENGLTESTER=ON \
            -DWITH_FONTCONVERTER=ON \
            -DWITH_GL_INFO=ON \
            -DWITH_GLFWAPPLICATION=ON \
            -DWITH_SDL2APPLICATION=ON \
            -DWITH_TGAIMAGECONVERTER=ON \
            -DWITH_TGAIMPORTER=ON \
            -DWITH_VK=ON \
            -DWITH_WAVAUDIOIMPORTER=ON \
            -DWITH_WINDOWLESSWGLAPPLICATION=ON \
            -DVulkan_LIBRARY=${MINGW_PREFIX}/lib/libvulkan.dll.a \
            "${extra_config[@]}" \
            ../${_realname}-${pkgver}
    ninja
}

package() {
    cd "${srcdir}"/build-${CARCH}
    DESTDIR="${pkgdir}" ninja install

    install -Dm644 "${srcdir}/${_realname}-${pkgver}/COPYING" \
        "${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}/COPYING"
}
